package com.mxx.common.netty.http.validate;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.validation.Validation;
import javax.validation.ValidatorFactory;

/**
 * @author: mxx
 * @date: 2021/9/26
 * @time: 13:59
 * @Description: 描述信息
 */
@Configuration
public class ValidatorConfig {
    /**
     * 创建验证器工厂
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(ValidatorFactory.class)
    public ValidatorFactory validatorFactory() {
        return Validation.buildDefaultValidatorFactory();
    }

    @Bean
    public JavaxMethodValidator javaxMethodValidator(ValidatorFactory validatorFactory) {
        return new JavaxMethodValidator(validatorFactory);
    }

}
